/**
 * 公共方法类
 */
layui.define(['layer'], function (exports) {

    var $ = layui.jquery;
    var layer = layui.layer;

    var comm = {

        /**
         * 发送ajax post请求
         * @param url 请求url
         * @param requestParam 请求参数对象
         * @param successfn 请求成功后执行的函数
         */
        post: function (url, requestParam, successfn) {
            $.ajax({
                type: 'post',
                url: url,
                data: JSON.stringify(requestParam),
                dataType: "json",
                contentType: 'application/json;charset=UTF-8',
                success: function (data) {
                    successfn(data);
                },
                error: function (error) {
                    layer.msg('系统异常');
                }
            });
        },


        /**
         * 发送ajax get请求
         * @param url 请求url
         * @param successfn 请求成功后执行的函数
         */
        get: function (url, successfn) {
            $.ajax({
                type: 'get',
                url: url,
                success: function (data) {
                    successfn(data);
                },
                error: function (error) {
                    layer.msg('系统异常');
                }
            });
        },

        open: function (dom, yesfn) {
            layer.open({
                type: 1,
                anim: 4,
                area: ['60%', '80%'],
                content: dom,
                btn: ['确认', '取消'],
                yes: function (index, layero) {
                    yesfn(index, layero);
                }
            });
        },

        openFull: function (dom, yesfn) {
            layer.open({
                type: 1,
                anim: 4,
                area: ['100%', '100%'],
                content: dom,
                btn: ['确认', '取消'],
                yes: function (index, layero) {
                    yesfn(index, layero);
                }
            });
        },

        getFormData: function (formId) {
            var o = {};
            var a = $('#' + formId).serializeArray();
            $.each(a, function () {
                if (o[this.name]) {
                    if (!o[this.name].push) {
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });
            return o;
        }
        , getFullHeight: function () {
            return $(window).height() - ($('.my-btn-box').outerHeight(true) ? $('.my-btn-box').outerHeight(true) + 35 : 40);
        }
    }

    exports('comm', comm);
});